﻿
//------------------------------------------------------------------------------

using System;
using System.Linq;
using Apps.Models;
using System.Data;
using Apps.IDAL.MIS;

namespace Apps.DAL.MIS
{
    public partial class MIS_ArticleRepository
    {
        /// <summary>
        /// 删除一个实体
        /// </summary>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">主键ID</param>
        public int Delete(string id,string userId)
        {
                MIS_Article entity = new MIS_Article();
                if (string.IsNullOrEmpty(userId))
                {
                    entity = Context.MIS_Article.SingleOrDefault(a => a.Id == id);
                }
                else {
                    entity = Context.MIS_Article.SingleOrDefault(a => a.Id == id && a.Creater == userId);
                }
                if (entity != null)
                {
                    Context.MIS_Article.Remove(entity);
                }
                return this.SaveChanges();
        }
       
        /// <summary>
        /// 获得名称
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>名称</returns>
        public string GetNameById(string id)
        {
            using (DBContainer db = new DBContainer())
            {
                var entity = db.MIS_Article.SingleOrDefault(s => s.Id == id);
                return entity == null ? "" : entity.Title;
            }
        
        }
    }
}
